package lambda_expression.stream;

import lambda_expression.method_reference.Employee;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

public class CreateStreamTest {

    public static void main(String[] args) throws IOException {
        /**
         * 通过文件创建流
         * java nio
         */
        Stream<String> stream =
                Files.lines(Paths.get("D:\\guonan\\project\\myroom\\lambda_expression\\lambda_demo1\\src\\main\\java\\lambda_expression\\stream\\DistinctStreamTest.java"));
        stream.forEach(System.out::println);

        /**
         * 通过函数生成流(无限流)
         */
        // 生成偶数流
        Stream stream1 = Stream.iterate(0, n -> n+2);
        stream1.limit(10).forEach(x -> System.out.print(x+" ")); // 0 2 4 6 8 10 12 14 16 18

        System.out.println();

        // 生成随机数流
        Stream stream2 = Stream.generate(Math::random);
        stream2.limit(10).forEach(x -> System.out.print(x+","));

    }
}
